# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[ActionItem.__init__(self, action=self._check_action, **kw)
self.depth = 1
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e390c>}
nname: 0
n 0(None)[from pygui.window.core import Button
from pygui.window import ConfirmWindow
w = ConfirmWindow(text=_("You are about to reset the box. Are you sure you want to do it?\nIf 'Yes', box will reboot."), confirm_action=self.reinit_box, buttons=[Button(_('Yes'), False), Button(_('No'), True)])
w.show()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3dec>}
nname: 0
n 0(None)[import os
from pygui.config import rw_dir
from pygui.facilities.power import reboot
f = open(os.path.join(rw_dir, 'reset-all'), 'w')
f.flush()
os.fsync(f.fileno())
f.close()
Task(reboot).start(delay=1)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3e4c>}
nname: 6
n 6(None)[def __init__(self, *args, **args):
	ActionItem.__init__(self, action=self._check_action, **kw)
	self.depth = 1

def _check_action(self):
	from pygui.window.core import Button
	from pygui.window import ConfirmWindow
	w = ConfirmWindow(text=_("You are about to reset the box. Are you sure you want to do it?\nIf 'Yes', box will reboot."), confirm_action=self.reinit_box, buttons=[Button(_('Yes'), False), Button(_('No'), True)])
	w.show()

def reinit_box(self):
	import os
	from pygui.config import rw_dir
	from pygui.facilities.power import reboot
	f = open(os.path.join(rw_dir, 'reset-all'), 'w')
	f.flush()
	os.fsync(f.fileno())
	f.close()
	Task(reboot).start(delay=1)

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76e330c>}
nname: 0
n 0(None)[_root = RootItem()
self._music = list(_root.browse(universe='audio', menu=self.menu))
self._image_video = list(_root.browse(universe='video_image', menu=self.menu))
self._tv = list(_root.browse(universe='tv', menu=self.menu))
self.items = [UniverseDeleteItem(_('TV'), 'tv', [], menu=self.menu), UniverseDeleteItem(_('Audio'), 'audio', self._music, menu=self.menu), UniverseDeleteItem(_('Video/Photo'), 'image_video', self._image_video, menu=self.menu), UniverseDeleteItem(_('All'), 'all', self._music, menu=self.menu)]
return self.items + [ConfirmDeleteItem(_('Confirm'), 'setupitem', self.confirm)]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e994c>}
nname: 0
n 0(None)[from pygui.window import ConfirmWindow
cw = ConfirmWindow(_('Delete %s ?' % '\n'.join(self._get_universes_to_delete())), confirm_action=self._delete)
cw.buttons[1].connect(self._uncheck_all_items)
cw.show()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3fec>}
nname: 62
n 62(None)[self._uncheck_all_items()
]:
	i: 0(AL), 61()
	o: 

nname: 61
n 61(None)[]:
	i: 15(AF), 57()
	o: 62()

nname: 57
n 57(None)[]:
	i: 25(f), 43()
	o: 61()

nname: 43
n 43(None)[it.delete_content()
continue
]:
	i: 25(t)
	o: 57()

nname: 25
n 25(it._universe in univ_to_delete)[for it in self.items:
]:
	i: 15(for)
	o: 43(t), 57(f)

nname: 15
n 15(None)[]:
	i: 0(loop)
	o: 25(for), 61(AF)

nname: 0
n 0(None)[univ_to_delete = self._get_universes_to_delete()
]:
	i: 
	o: 15(loop), 62(AL)

nname: 62
n 62(None)[self._uncheck_all_items()
]:
	i: 0(AL), 15(AF), 25()
	o: 

nname: 25
n 25(None)[for it in self.items:
if it._universe in univ_to_delete:
	it.delete_content()
	continue
]:
	i: 15(for)
	o: 62()

nname: 15
n 15(None)[]:
	i: 0(loop)
	o: 25(for), 62(AF)

nname: 0
n 0(None)[univ_to_delete = self._get_universes_to_delete()
]:
	i: 
	o: 15(loop), 62(AL)

nname: 25
n 25(None)[for it in self.items:
	if it._universe in univ_to_delete:
		it.delete_content()
		continue
self._uncheck_all_items()
]:
	i: 0(for)
	o: 

nname: 0
n 0(None)[univ_to_delete = self._get_universes_to_delete()
]:
	i: 
	o: 25(for)

nname: 0
n 0(None)[univ_to_delete = self._get_universes_to_delete()
for it in self.items:
	if it._universe in univ_to_delete:
		it.delete_content()
		continue
self._uncheck_all_items()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3f2c>}
nname: 47
n 47(None)[del _[1]
return self.items
]:
	i: 0(AF), 43()
	o: 

nname: 43
n 43(None)[]:
	i: 17(f), 29()
	o: 47()

nname: 29
n 29(None)[continue
]:
	i: 17(t)
	o: 43()

nname: 17
n 17(it.to_delete)[for it in self.items:
]:
	i: 0(for)
	o: 29(t), 43(f)

nname: 0
n 0(None)[]:
	i: 
	o: 17(for), 47(AF)

nname: 47
n 47(None)[del _[1]
return self.items
]:
	i: 0(AF), 17()
	o: 

nname: 17
n 17(None)[for it in self.items:
if it.to_delete:
	continue
]:
	i: 0(for)
	o: 47()

nname: 0
n 0(None)[]:
	i: 
	o: 17(for), 47(AF)

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3dac>, 17: <unpyclib.structure.node instance at 0xb76e3f8c>, 47: <unpyclib.structure.node instance at 0xb76e3fec>}
nname: 29
n 29(None)[]:
	i: 0(AL), 28()
	o: 

nname: 28
n 28(None)[]:
	i: 3(AF), 13()
	o: 29()

nname: 13
n 13(None)[for it in self.items:
it.to_delete = False
]:
	i: 3(for)
	o: 28()

nname: 3
n 3(None)[]:
	i: 0(loop)
	o: 13(for), 28(AF)

nname: 0
n 0(None)[]:
	i: 
	o: 3(loop), 29(AL)

nname: 29
n 29(None)[]:
	i: 13()
	o: 

nname: 13
n 13(None)[for it in self.items:
	it.to_delete = False
]:
	i: 0(for)
	o: 29()

nname: 0
n 0(None)[]:
	i: 
	o: 13(for)

nname: 29
n 29(None)[]:
	i: 0()
	o: 

nname: 0
n 0(None)[for it in self.items:
	it.to_delete = False
]:
	i: 
	o: 29()

nname: 0
n 0(None)[for it in self.items:
	it.to_delete = False
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3fec>}
nname: 6
n 6(None)[__doc__ = "\n    Handle the retrieval of each universes' size and their contents suppress\n    "
depth = 2
def browse(self):
	_root = RootItem()
	self._music = list(_root.browse(universe='audio', menu=self.menu))
	self._image_video = list(_root.browse(universe='video_image', menu=self.menu))
	self._tv = list(_root.browse(universe='tv', menu=self.menu))
	self.items = [UniverseDeleteItem(_('TV'), 'tv', [], menu=self.menu), UniverseDeleteItem(_('Audio'), 'audio', self._music, menu=self.menu), UniverseDeleteItem(_('Video/Photo'), 'image_video', self._image_video, menu=self.menu), UniverseDeleteItem(_('All'), 'all', self._music, menu=self.menu)]
	return self.items + [ConfirmDeleteItem(_('Confirm'), 'setupitem', self.confirm)]

def confirm(self):
	from pygui.window import ConfirmWindow
	cw = ConfirmWindow(_('Delete %s ?' % '\n'.join(self._get_universes_to_delete())), confirm_action=self._delete)
	cw.buttons[1].connect(self._uncheck_all_items)
	cw.show()

def _delete(self):
	univ_to_delete = self._get_universes_to_delete()
	for it in self.items:
		if it._universe in univ_to_delete:
			it.delete_content()
			continue
	self._uncheck_all_items()

def _get_universes_to_delete(self):
	pass

def _uncheck_all_items(self):
	for it in self.items:
		it.to_delete = False

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76e388c>}
nname: 0
n 0(None)[self._universe = universe
self.universe_name = universe_name
self.related_items = related_items
self._to_delete = False
self._total_size = 0
name = '%s %s' % (universe_name, bytes_to_human(sum(<genexpr>(related_items))))
ActionItem.__init__(self, name, type_='setupitem', display_type='not_checked', *args, **kw)
self.action = self._action
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e91ec>}
nname: 0
n 0(None)[self.to_delete = not self.to_delete
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3f2c>}
nname: 26
n 26(None)[self.display_type = 'checked'
self.reset_view()
]:
	i: 15(), 22()
	o: 

nname: 22
n 22(None)[]:
	i: 0(t)
	o: 26()

nname: 15
n 15(None)[]:
	i: 0(f)
	o: 26()

nname: 0
n 0(value)[self._to_delete = value
]:
	i: 
	o: 15(f), 22(t)

nname: 0
n 0(None)[self._to_delete = value
if not value:
	pass
self.display_type = 'checked'
self.reset_view()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3b0c>}
nname: 0
n 0(None)[return self._to_delete
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3a0c>}
nname: 0
n 0(None)[return self._to_delete
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3e4c>}
nname: 0
n 0(None)[print 'DELETE',
print self._universe
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e3d6c>}
nname: 6
n 6(None)[def __init__(self, universe_name, universe, related_items, *args, **args):
	self._universe = universe
	self.universe_name = universe_name
	self.related_items = related_items
	self._to_delete = False
	self._total_size = 0
	name = '%s %s' % (universe_name, bytes_to_human(sum(<genexpr>(related_items))))
	ActionItem.__init__(self, name, type_='setupitem', display_type='not_checked', *args, **kw)
	self.action = self._action

def _action(self):
	self.to_delete = not self.to_delete

def _set_to_delete(self, value):
	self._to_delete = value
	if not value:
		pass
	self.display_type = 'checked'
	self.reset_view()

to_delete = property((lambda self: self._to_delete), _set_to_delete)
del _set_to_delete
def delete_content(self):
	print 'DELETE',
	print self._universe

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76e3c8c>}
nname: 0
n 0(None)[ActionItem.__init__(self, name, type_, action=action, *args, **kw)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e336c>}
nname: 6
n 6(None)[def __init__(self, name, type_, action, *args, **args):
	ActionItem.__init__(self, name, type_, action=action, *args, **kw)

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76e31ac>}
nname: 0
n 0(None)[from __future__ import absolute_import
from ...core import ActionItem
from ...containers import GenericContainer
from ...mediaitem import RootItem
from peewee.formatters import bytes_to_human
from peewee.notifier import Task
class ReInitBoxItem(ActionItem):
	def __init__(self, *args, **args):
		ActionItem.__init__(self, action=self._check_action, **kw)
		self.depth = 1

	def _check_action(self):
		from pygui.window.core import Button
		from pygui.window import ConfirmWindow
		w = ConfirmWindow(text=_("You are about to reset the box. Are you sure you want to do it?\nIf 'Yes', box will reboot."), confirm_action=self.reinit_box, buttons=[Button(_('Yes'), False), Button(_('No'), True)])
		w.show()

	def reinit_box(self):
		import os
		from pygui.config import rw_dir
		from pygui.facilities.power import reboot
		f = open(os.path.join(rw_dir, 'reset-all'), 'w')
		f.flush()
		os.fsync(f.fileno())
		f.close()
		Task(reboot).start(delay=1)



class DeleteContentsItem(GenericContainer):
	__doc__ = "\n    Handle the retrieval of each universes' size and their contents suppress\n    "
	depth = 2
	def browse(self):
		_root = RootItem()
		self._music = list(_root.browse(universe='audio', menu=self.menu))
		self._image_video = list(_root.browse(universe='video_image', menu=self.menu))
		self._tv = list(_root.browse(universe='tv', menu=self.menu))
		self.items = [UniverseDeleteItem(_('TV'), 'tv', [], menu=self.menu), UniverseDeleteItem(_('Audio'), 'audio', self._music, menu=self.menu), UniverseDeleteItem(_('Video/Photo'), 'image_video', self._image_video, menu=self.menu), UniverseDeleteItem(_('All'), 'all', self._music, menu=self.menu)]
		return self.items + [ConfirmDeleteItem(_('Confirm'), 'setupitem', self.confirm)]

	def confirm(self):
		from pygui.window import ConfirmWindow
		cw = ConfirmWindow(_('Delete %s ?' % '\n'.join(self._get_universes_to_delete())), confirm_action=self._delete)
		cw.buttons[1].connect(self._uncheck_all_items)
		cw.show()

	def _delete(self):
		univ_to_delete = self._get_universes_to_delete()
		for it in self.items:
			if it._universe in univ_to_delete:
				it.delete_content()
				continue
		self._uncheck_all_items()

	def _get_universes_to_delete(self):
		pass

	def _uncheck_all_items(self):
		for it in self.items:
			it.to_delete = False



class UniverseDeleteItem(ActionItem):
	def __init__(self, universe_name, universe, related_items, *args, **args):
		self._universe = universe
		self.universe_name = universe_name
		self.related_items = related_items
		self._to_delete = False
		self._total_size = 0
		name = '%s %s' % (universe_name, bytes_to_human(sum(<genexpr>(related_items))))
		ActionItem.__init__(self, name, type_='setupitem', display_type='not_checked', *args, **kw)
		self.action = self._action

	def _action(self):
		self.to_delete = not self.to_delete

	def _set_to_delete(self, value):
		self._to_delete = value
		if not value:
			pass
		self.display_type = 'checked'
		self.reset_view()

	to_delete = property((lambda self: self._to_delete), _set_to_delete)
	del _set_to_delete
	def delete_content(self):
		print 'DELETE',
		print self._universe



class ConfirmDeleteItem(ActionItem):
	def __init__(self, name, type_, action, *args, **args):
		ActionItem.__init__(self, name, type_, action=action, *args, **kw)



]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76dbc6c>}
from __future__ import absolute_import
from ...core import ActionItem
from ...containers import GenericContainer
from ...mediaitem import RootItem
from peewee.formatters import bytes_to_human
from peewee.notifier import Task
class ReInitBoxItem(ActionItem):
	def __init__(self, *args, **args):
		ActionItem.__init__(self, action=self._check_action, **kw)
		self.depth = 1

	def _check_action(self):
		from pygui.window.core import Button
		from pygui.window import ConfirmWindow
		w = ConfirmWindow(text=_("You are about to reset the box. Are you sure you want to do it?\nIf 'Yes', box will reboot."), confirm_action=self.reinit_box, buttons=[Button(_('Yes'), False), Button(_('No'), True)])
		w.show()

	def reinit_box(self):
		import os
		from pygui.config import rw_dir
		from pygui.facilities.power import reboot
		f = open(os.path.join(rw_dir, 'reset-all'), 'w')
		f.flush()
		os.fsync(f.fileno())
		f.close()
		Task(reboot).start(delay=1)



class DeleteContentsItem(GenericContainer):
	__doc__ = "\n    Handle the retrieval of each universes' size and their contents suppress\n    "
	depth = 2
	def browse(self):
		_root = RootItem()
		self._music = list(_root.browse(universe='audio', menu=self.menu))
		self._image_video = list(_root.browse(universe='video_image', menu=self.menu))
		self._tv = list(_root.browse(universe='tv', menu=self.menu))
		self.items = [UniverseDeleteItem(_('TV'), 'tv', [], menu=self.menu), UniverseDeleteItem(_('Audio'), 'audio', self._music, menu=self.menu), UniverseDeleteItem(_('Video/Photo'), 'image_video', self._image_video, menu=self.menu), UniverseDeleteItem(_('All'), 'all', self._music, menu=self.menu)]
		return self.items + [ConfirmDeleteItem(_('Confirm'), 'setupitem', self.confirm)]

	def confirm(self):
		from pygui.window import ConfirmWindow
		cw = ConfirmWindow(_('Delete %s ?' % '\n'.join(self._get_universes_to_delete())), confirm_action=self._delete)
		cw.buttons[1].connect(self._uncheck_all_items)
		cw.show()

	def _delete(self):
		univ_to_delete = self._get_universes_to_delete()
		for it in self.items:
			if it._universe in univ_to_delete:
				it.delete_content()
				continue
		self._uncheck_all_items()

	def _get_universes_to_delete(self):
		pass

	def _uncheck_all_items(self):
		for it in self.items:
			it.to_delete = False



class UniverseDeleteItem(ActionItem):
	def __init__(self, universe_name, universe, related_items, *args, **args):
		self._universe = universe
		self.universe_name = universe_name
		self.related_items = related_items
		self._to_delete = False
		self._total_size = 0
		name = '%s %s' % (universe_name, bytes_to_human(sum(<genexpr>(related_items))))
		ActionItem.__init__(self, name, type_='setupitem', display_type='not_checked', *args, **kw)
		self.action = self._action

	def _action(self):
		self.to_delete = not self.to_delete

	def _set_to_delete(self, value):
		self._to_delete = value
		if not value:
			pass
		self.display_type = 'checked'
		self.reset_view()

	to_delete = property((lambda self: self._to_delete), _set_to_delete)
	del _set_to_delete
	def delete_content(self):
		print 'DELETE',
		print self._universe



class ConfirmDeleteItem(ActionItem):
	def __init__(self, name, type_, action, *args, **args):
		ActionItem.__init__(self, name, type_, action=action, *args, **kw)



